<?php

namespace app\admin\model\jubao;

use think\Model;


class Hsh extends Model
{

    

    

    // 表名
    protected $name = 'jubao_hsh';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'type_text',
        'r_type_text',
        'r_sex_text',
        'r_id_info_text',
        'f_starttime_text',
        'f_endtime_text',
        'f_gang_text',
        'f_charge_text',
        'f_industry_text',
        's_exist_text',
        's_id_info_text',
        'status_text'
    ];
    

    
    public function getTypeList()
    {
        return ['personal' => __('Type personal'), 'company' => __('Type company')];
    }

    public function getRTypeList()
    {
        return ['personal' => __('R_type personal'), 'company' => __('R_type company')];
    }

    public function getRSexList()
    {
        return ['0' => __('R_sex 0'), '1' => __('R_sex 1'), '2' => __('R_sex 2')];
    }

    public function getRIdInfoList()
    {
        return ['0' => __('R_id_info 0'), '1' => __('R_id_info 1'), '2' => __('R_id_info 2'), '3' => __('R_id_info 3'), '4' => __('R_id_info 4'), '5' => __('R_id_info 5'), '6' => __('R_id_info 6'), '7' => __('R_id_info 7')];
    }

    public function getFGangList()
    {
        return ['1' => __('F_gang 1'), '2' => __('F_gang 2'), '3' => __('F_gang 3'), '4' => __('F_gang 4'), '5' => __('F_gang 5')];
    }

    public function getFChargeList()
    {
        return ['1' => __('F_charge 1'), '2' => __('F_charge 2'), '3' => __('F_charge 3'), '4' => __('F_charge 4'), '5' => __('F_charge 5'), '6' => __('F_charge 6'), '7' => __('F_charge 7'), '8' => __('F_charge 8'), '9' => __('F_charge 9'), '10' => __('F_charge 10'), '11' => __('F_charge 11'), '12' => __('F_charge 12'), '13' => __('F_charge 13'), '14' => __('F_charge 14'), '15' => __('F_charge 15'), '16' => __('F_charge 16'), '17' => __('F_charge 17'), '18' => __('F_charge 18'), '19' => __('F_charge 19')];
    }

    public function getFIndustryList()
    {
        return ['1' => __('F_industry 1'), '2' => __('F_industry 2'), '3' => __('F_industry 3'), '4' => __('F_industry 4'), '5' => __('F_industry 5'), '6' => __('F_industry 6'), '7' => __('F_industry 7'), '8' => __('F_industry 8'), '9' => __('F_industry 9'), '10' => __('F_industry 10'), '11' => __('F_industry 11'), '12' => __('F_industry 12'), '13' => __('F_industry 13'), '14' => __('F_industry 14'), '15' => __('F_industry 15'), '16' => __('F_industry 16')];
    }

    public function getSExistList()
    {
        return ['0' => __('S_exist 0'), '1' => __('S_exist 1'), '2' => __('S_exist 2')];
    }

    public function getSIdInfoList()
    {
        return ['1' => __('S_id_info 1'), '2' => __('S_id_info 2'), '3' => __('S_id_info 3'), '4' => __('S_id_info 4'), '5' => __('S_id_info 5'), '0' => __('S_id_info 0')];
    }

    public function getStatusList()
    {
        return ['1' => __('Status 1'), '2' => __('Status 2'), '3' => __('Status 3')];
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getRTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['r_type']) ? $data['r_type'] : '');
        $list = $this->getRTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getRSexTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['r_sex']) ? $data['r_sex'] : '');
        $list = $this->getRSexList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getRIdInfoTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['r_id_info']) ? $data['r_id_info'] : '');
        $list = $this->getRIdInfoList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getFStarttimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['f_starttime']) ? $data['f_starttime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getFEndtimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['f_endtime']) ? $data['f_endtime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getFGangTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['f_gang']) ? $data['f_gang'] : '');
        $list = $this->getFGangList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getFChargeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['f_charge']) ? $data['f_charge'] : '');
        $valueArr = explode(',', $value);
        $list = $this->getFChargeList();
        return implode(',', array_intersect_key($list, array_flip($valueArr)));
    }


    public function getFIndustryTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['f_industry']) ? $data['f_industry'] : '');
        $valueArr = explode(',', $value);
        $list = $this->getFIndustryList();
        return implode(',', array_intersect_key($list, array_flip($valueArr)));
    }


    public function getSExistTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['s_exist']) ? $data['s_exist'] : '');
        $valueArr = explode(',', $value);
        $list = $this->getSExistList();
        return implode(',', array_intersect_key($list, array_flip($valueArr)));
    }


    public function getSIdInfoTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['s_id_info']) ? $data['s_id_info'] : '');
        $list = $this->getSIdInfoList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setFStarttimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setFEndtimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setFChargeAttr($value)
    {
        return is_array($value) ? implode(',', $value) : $value;
    }

    protected function setFIndustryAttr($value)
    {
        return is_array($value) ? implode(',', $value) : $value;
    }

    protected function setSExistAttr($value)
    {
        return is_array($value) ? implode(',', $value) : $value;
    }
    public function gangCrimes($data)
    {
        unset($data['id']);
        unset($data['status']);
        unset($data['createtime']);
        unset($data['updatetime']);
        return $this->data($data)->allowField(true)->isUpdate(false)->save();
        // return $this->allowField(true)->strict(false)->insertGetId($data);
    }

}
